//
//  WKBeautysayDetailVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/21.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKBeautysayDetailVC.h"
#import "WKBeautysayDetailView.h"
#import "JXPagerView.h"
#import "JXCategoryView.h"
#import "WKCommentListView.h"


@interface WKBeautysayDetailVC ()<JXCategoryViewDelegate,UIScrollViewDelegate>
{
    WKBeautysayDetailView *_headerView;
}
@property(nonatomic,strong)UIView *maninHeaderView;
@property(nonatomic,strong)UIButton *hotBtn;
@property(nonatomic,strong)JXCategoryTitleView *categoryView;
@end

@implementation WKBeautysayDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
}

- (void)initViews{
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.naviBar.title = @"美说详情";
   
   
    
   
  
    
   
    WKCommentListView *view1 = [[WKCommentListView alloc]init];
    WKCommentListView *view2 = [[WKCommentListView alloc]init];
    
    
    _listViewArray = @[view1,view2];
    
    self.maninHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    self.hotBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_hotBtn setTitle:@"按热度" forState:UIControlStateNormal];
    [_hotBtn setTitleColor:UIColorFromHex(0x979797) forState:UIControlStateNormal];
    _hotBtn.titleLabel.font = PFSC_MediumFont(11);
    [_hotBtn setImage:ImageNamed(@"triangle_down") forState:UIControlStateNormal];
    _hotBtn.frame = CGRectMake(ScreenWidth-10-60, 15, 60, 14);
    [_hotBtn layoutButtonWithEdgeInsetsStyle:WHButtonEdgeInsetsStyleRight imageTitleSpace:5];
    [_maninHeaderView addSubview:_hotBtn];
    [_maninHeaderView addSubview:[WHFactory addLineWithFrame:CGRectMake(0, 43, ScreenWidth, 1)]];
    
    
    _headerView = [[WKBeautysayDetailView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 530)];
    _headerView.backgroundColor = [UIColor yellowColor];
    
    NSArray *titleArr = @[@"全部评论",@"全部转发"];
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    self.categoryView.titles = titleArr;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = UIColorFromHex(0x3C3C3C);
    self.categoryView.titleColor = UIColorFromHex(0x979797);
    self.categoryView.titleFont = PFSC_MediumFont(15);
    self.categoryView.titleColorGradientEnabled = NO;
    self.categoryView.titleLabelZoomEnabled = NO;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = BACK_COLOR;
    lineView.indicatorLineWidth = 35;
    self.categoryView.indicators = @[lineView];
    
    [self.maninHeaderView addSubview:self.categoryView];
    
    
//    self.categoryView.contentScrollView = _scrollView;
    
    _pagerView = [self preferredPagingView];
    
    [self.view addSubview:_pagerView];
    
     self.categoryView.contentScrollView = self.pagerView.listContainerView.collectionView;
    

    
    //扣边返回处理，下面的代码要加上
    [self.pagerView.listContainerView.collectionView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
    [self.pagerView.mainTableView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
    
    //让mainTableView可以显示范围外
//    self.pagerView.mainTableView.clipsToBounds = false;
    
    _headerView.frame = CGRectMake(0, 0, ScreenWidth,  530);
   
}



- (JXPagerView *)preferredPagingView {
    return [[JXPagerView alloc] initWithDelegate:self];

}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    self.pagerView.frame = CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight-NavBarHeight);
}

#pragma mark - JXPagerViewDelegate

- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
    return _headerView;
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    return 530;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return 44;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
//    return self.categoryView;
    return self.maninHeaderView;
}

- (NSArray<id<JXPagerViewListViewDelegate>> *)listViewsInPagerView:(JXPagerView *)pagerView {
    return self.listViewArray;
}

#pragma mark - JXCategoryViewDelegate

- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    
    _hotBtn.hidden = index == 0 ? NO : YES;
    NSLog(@"%ld",index);
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
    
    
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
